<template>
  <div v-if="data !== undefined" id="index">
    <el-card class="box-card">
      <el-row>
        <el-col :span="2">{{ data.checkedAddress.name }}</el-col>
        <el-col :span="2">{{ data.checkedAddress.tel }}</el-col>
        <el-col :span="20">{{ data.checkedAddress.province + data.checkedAddress.city + data.checkedAddress.county + data.checkedAddress.addressDetail }}</el-col>
      </el-row>
    </el-card>
    <el-card class="box-card">
      <el-row v-for="(item,index) in data.checkedGoodsList" :key="index" style="background-color: #fcfcfc;border: 1px solid #cccccc;padding: 15px;margin-top: 20px;">
        <el-col :span="24">
          <el-col :span="12">
            <el-row>
              <el-col :span="6">
                <el-image style="width: 100px;height: 100px;margin-left: 10px;" fit="cover" :src="item.picUrl" />
              </el-col>
              <el-col :span="16">{{ item.goodsName }}</el-col>
            </el-row>
          </el-col>
          <el-col :span="3" class="row-line-text">
            ￥{{ item.price }}
          </el-col>
          <el-col :span="3" class="row-line-text">
            <el-input-number v-model="item.number" :min="1" size="mini" :disabled="true" />
          </el-col>
          <el-col :span="3" class="row-line-text" style="color: #ff4400">￥{{ item.price * item.number }}</el-col>
        </el-col>
      </el-row>
    </el-card>
    <el-card class="box-card">
      <el-row>
        <el-col :span="24">商品合计<span style="display: inline-block; float: right;">￥{{ data.goodsTotalPrice }}元</span></el-col>
      </el-row>
      <el-divider />
      <el-row>
        <el-col :span="24">运费<span style="display: inline-block; float: right;">￥{{ data.freightPrice }}元</span></el-col>
      </el-row>
      <el-divider />
      <el-row>
        <el-col :span="24"><el-input v-model="message" placeholder="如有需要，请留言!" /></el-col>
      </el-row>
    </el-card>
    <el-row>
      <el-col :span="24">实付：￥{{ data.orderTotalPrice }}元<el-button type="primary" style="float: right;" @click="submit">确认下单</el-button></el-col>
    </el-row>
  </div>
</template>

<script>
import { checkout } from '@/api/webSite/ApiCart'
import { submit } from '@/api/webSite/ApiOrder'
class OrderParam {
  constructor(cartId, addressId, couponId, userCouponId, grouponRulesId, grouponLinkId, message) {
    this.cartId = cartId
    this.addressId = addressId
    this.couponId = couponId
    this.userCouponId = userCouponId
    this.grouponRulesId = grouponRulesId
    this.grouponLinkId = grouponLinkId
    this.message = message
  }
}
export default {
  name: 'Index',
  data() {
    return {
      data: undefined,
      message: ''
    }
  },
  mounted() {
    checkout({ cartId: this.$route.query.cartId }).then(res => {
      this.data = res.data.data
    })
  },
  methods: {
    submit() {
      const { cartId, couponId, userCouponId, grouponRulesId } = this.data
      submit(new OrderParam(cartId, this.data.checkedAddress.id, couponId, userCouponId, grouponRulesId, undefined, this.message)).then(res => {
        if (res.data.code === 200) {
          this.$message.success('订单提交成功！')
        }
      })
    }
  }
}
</script>

<style scoped>
#index {
  width: 100%;
  padding-top: 20px;
}
.box-card {
  margin-bottom: 20px;
}
.row-line-text {
  height: 100px;
  line-height: 100px;
}
</style>
